#include <iostream>
#include <fstream>

#include	"ContentFile.hpp"

void		ContentFile::replaceTabulation(std::string & str)
{
  int pos;
  int	count;
  std::string	a;
  
  while ((pos = str.find('\t')) != std::string::npos)
    {
      count = 0;
      a.clear();
      count = 4 - (pos % 4); 
      if (count > 0 && count > 0)
	count += 4;
      while (count > 0)
	{
	  a.push_back('.');
	  count--;
	}
      str.replace(pos, 1, a);
    }
}

void		ContentFile::iterateList()
{
  std::list<std::string>::iterator	it;

  for (it = this->listContent.begin(); it != this->listContent.end(); it++)
    {
      replaceTabulation(*it);
    }
}

ContentFile::ContentFile(const char *nameFile)
{
  std::string	line;
  std::ifstream	myfile(nameFile);
  if (myfile.is_open())
    {
      while (myfile.good())
	{
	  getline(myfile,line);
	  std::cout << line << std::endl;
	  this->listContent.push_back(line);
	}
      myfile.close();
    }
  else
    std::cout << "Unable to open file";
  iterateList();
}

std::list<std::string>	ContentFile::getList()const
{
  return (this->listContent);
}

ContentFile::~ContentFile()
{

}
